using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class DetailsViewByCode : System.Web.UI.Page
{
    DetailsView detailsView ;
    protected void Page_Load(object sender, EventArgs e)
    {
         
            
            detailsView = new DetailsView();
            detailsView.AllowPaging=true;
            detailsView.PageIndexChanging += new DetailsViewPageEventHandler(detailsView_PageIndexChanging);    
            detailsView.HeaderText="Account Details";  
            detailsView.HeaderStyle.Font.Bold=true;      
            this.form1.Controls.Add(detailsView);
            if (!IsPostBack)
            {
                FillData(detailsView);
             }
    }

    void detailsView_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
    {
        
        
        detailsView.PageIndex = e.NewPageIndex;
        FillData(detailsView);
    }
    void FillData(DetailsView detailsView)
    {
        SqlDataSource sqlDataSource = 
        new SqlDataSource();
        sqlDataSource.ConnectionString=
        WebConfigurationManager.ConnectionStrings[
        "RecruitVietnamDbConnectionString"].ConnectionString;
        sqlDataSource.SelectCommand=
        "Select Email,CompanyName,ContactName,"+
        "Address,Phone from tblRCAccounts";
        detailsView.DataSource=sqlDataSource;
        detailsView.DataBind();
    }
}
